package com.test.config;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .select()
                //扫描那个接口的包
                .apis(RequestHandlerSelectors.basePackage("com.test.controller"))
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title("收集jconsole指标日志")
                        .description("收集jconsole指标日志")
                        .version("1.1")
                        .build());
    }

    /**
     * 更新时间戳到日志文件中
     * @return
     */
    @Bean
    public String deleteLogFile() {
        FileUtil.appendUtf8String("\n============" + DateUtil.now() + "============\n\n", "/root/collect_springboot.log");
        return "";
    }
}